package com.mainaer.wjokhttp;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;

import com.mainaer.wjokhttp.ui.MainActivity;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.concurrent.CountDownLatch;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard;
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.matcher.ViewMatchers.withId;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class MainActivityTest {

    @Rule
    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
            MainActivity.class);

    @Test
    public void Run() {
        onView(withId(R.id.search_src_text)).perform(typeText("tom and jerry"), closeSoftKeyboard());
        onView(withId(R.id.search_go_btn)).perform(click());

        // 防止自动退出
        CountDownLatch countdown = new CountDownLatch(1);
        try {
            countdown.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

}
